﻿/// <reference path="jquery-1.7.2-vsdoc.js" />
(function ($, undefined) {
    $.aspnetAjax = function (method, postData, onSuccess, onError) {
        ///<summary>ASP.NET AJAX4.0使用jQuery调用方法。</summary>
        ///<param name="method" type="string">服务端方法名称。</param>
        ///<param name="postData" type="JSON">[可选]服务端方法参数JSON值（注意大小写，IE6,IE7需要引用json2.js）。</param>
        ///<param name="onSuccess" type="function">[可选]执行正确后的回调函数。</param>
        ///<param name="onError" type="function">[可选]发生错误时回调函数。</param>
        postData = postData || {};
        onSuccess = onSuccess || function (data) { alert(JSON.stringify(data)); }
        onError = onError || function (e) { alert(e.responseText); }
        var url = (function () {
            var path = location.pathname;
            if (path[path.length - 1] == '/')
                path += 'default.aspx';
            return path + '/';
        })();
        url += method;
        $.ajax(
        {
            type: "POST",
            contentType: "application/json",
            url: url,
            data: JSON.stringify(postData || {}),
            dataType: "json",
            success: function (msg) {
                onSuccess(msg.d);
            },
            error: function (e) {
                onError(e);
            }
        });
    };
})(jQuery);